home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / pcgen.asm < prev    next >
Assembly Source File  |  1994-07-11  |  6KB  |  344 lines

  1.     include    pmacros.h
  2.  
  3. dseg
  4. jtable    dw    l0,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15    
  5. pubvar    sssave,<dw ?>
  6. pubvar    spsave,<dw ?>
  7.     db    512 dup(?)
  8. pubvar    intstk,<label byte>
  9. pubvar    mtasker,<db ?>
  10. extvar    isat,<byte>
  11. dsegend
  12.  
  13. ; common routine for interrupt return
  14.     pubproc    doret
  15.     pop    es
  16.     pop    di
  17.     pop    si
  18.     pop    bp
  19.     pop    dx
  20.     pop    cx
  21.     pop    bx
  22.     cmp    isat@,1
  23.     jnz    notat        ; Only one 8259, so skip this stuff
  24.     mov    al,0bh        ; read in-service register from
  25.     out    0a0h,al        ; secondary 8259
  26.     nop            ; settling delay
  27.     nop
  28.     nop
  29.     in    al,0a0h        ; get it
  30.     or    al,al        ; Any bits set?
  31.     jz    notat        ; nope, not a secondary interrupt
  32.     mov    al,20h        ; Get EOI instruction
  33.     out    0a0h,al        ; Secondary 8259 (PC/AT only)
  34. notat:    mov    al,20h        ; 8259 end-of-interrupt command
  35.     out    20h,al        ; Primary 8259
  36.     mov    ss,sssave@
  37.     mov    sp,spsave@    ; restore original stack context
  38.     pop    ds
  39.     pop    ax
  40.     iret
  41.     pend    doret
  42.  
  43. if TURBO
  44. else
  45. ; setvect - set interrupt vector
  46. ; called from C as follows
  47. ; setvect(vec,vecval)
  48. ; char vec;        /* Interrupt number */
  49. ; void (*vecval)();    /* offset (and segment in large code model) */
  50.  
  51.     procdef    setvect,<<vec,byte>,<ipval,fptr>>
  52.     mov    ah,25h
  53.     mov    al,vec
  54.     push    ds        ; save
  55. ifdef    LARGECODE
  56.     lds    dx,ipval
  57. else
  58.     mov    dx,ipval
  59.     push    cs
  60.     pop    ds
  61. endif
  62.     int    21h
  63.     pop    ds        ; restore
  64.     pret
  65.     pend    setvect
  66.  
  67. ; getvect - return current interrupt vector
  68. ; called from C as
  69. ; long        /* Returns CS in high word, IP in low word */
  70. ; getvect(vecnum)
  71. ; char vecnum;    /* Interrupt number */
  72.  
  73.     procdef    getvect,<<vecnum,byte>>
  74.     mov    ah,35h
  75.     mov    al,vecnum
  76.     push    es    ; save, since DOS uses it for a return value
  77.     int    21h
  78.     mov    dx,es    ; CS value into DX (C high word)
  79.     mov    ax,bx    ; IP value into AX (C low word)
  80.     pop    es    ; restore es
  81.     pret
  82.     pend    getvect
  83. endif
  84.  
  85. ; kbraw - raw, nonblocking read from console
  86. ; If character is ready, return it; if not, return -1
  87.  
  88.     procdef    kbraw
  89.     mov    ah,06h    ; Direct Console I/O
  90.     mov    dl,0ffh    ; Read from keyboard
  91.     int    21h    ; Call DOS
  92.     jz    nochar    ; zero flag set -> no character ready
  93.     mov    ah,0    ; valid char is 0-255
  94.     pret
  95. nochar:
  96.     mov    ax,-1    ; no char, return -1
  97.     pret
  98.     pend    kbraw
  99.  
  100. ; disable - disable interrupts and return previous state: 0 = disabled,
  101. ;           1 = enabled
  102.  
  103.     procdef    disable
  104.     pushf            ; save state on stack
  105.     cli            ; interrupts off
  106.     pop    ax        ; original flags -> ax
  107.     and    ax,200h        ; 1<<9 is IF bit
  108.     jnz    ion        ; nonzero -> interrupts were on
  109.     pret
  110. ion:    mov    ax,1
  111.     pret
  112.     pend    disable
  113.  
  114. ; restore - restore interrupt state: 0 = off, nonzero = on
  115.  
  116.     procdef    restore,<<istate,byte>>
  117.     test    istate,0ffh
  118.     jz    ioff
  119.     sti
  120. ioff:    pret
  121.     pend    restore
  122.  
  123. ; Halt until an interrupt occurs, then return
  124.     procdef eihalt
  125.     sti    ; make sure interrupts are enabled
  126.     hlt
  127.     pret
  128.     pend    eihalt
  129.  
  130. ; multitasker types
  131. NONE        equ    0
  132. DOUBLEDOS    equ    1
  133. DESQVIEW    equ    2
  134.  
  135. ; Relinquish processor so other task can run
  136.     procdef    giveup
  137.     cmp    mtasker@, DOUBLEDOS
  138.     jnz    givedesqview
  139.     mov    al,2        ; 110 ms
  140.     mov    ah,0eeh
  141.     int    21h
  142.  
  143. givedesqview:
  144.     cmp    mtasker@, DESQVIEW
  145.     jnz    notask
  146.     mov    ax, 1000h
  147.     int    15h
  148. notask:
  149.     pret
  150.     pend    giveup
  151.  
  152. ; check for a multitasker running
  153.     procdef chktasker
  154.     mov    mtasker@, NONE
  155.     ; do the doubledos test
  156.     mov    ah, 0e4h
  157.     int    21h
  158.     cmp    al, 1
  159.     jz    isdos
  160.     cmp    al, 2
  161.     jnz    test_desq
  162. isdos:    mov    mtasker@, DOUBLEDOS
  163.     pret
  164.  
  165.     ; test for desqview
  166. test_desq:
  167.     mov    ax, 2b01h
  168.     mov    cx, 4445h
  169.     mov    dx, 5351h
  170.     int    21h
  171.     cmp    al, 0ffh
  172.     jnz    isdesq
  173.     pret
  174. isdesq:    mov    mtasker@, DESQVIEW
  175.     pret
  176.     pend    chktasker
  177.  
  178. ; getds - Read DS for debugging purposes
  179.     procdef    getds
  180.     getds
  181.     pret
  182.     pend    getds
  183.  
  184. ; Internet checksum subroutine
  185. ; Compute 1's-complement sum of data buffer
  186. ; Uses an unwound loop inspired by "Duff's Device" for performance
  187. ;
  188. ; Called from C as
  189. ; unsigned short
  190. ; lcsum(buf,cnt)
  191. ; unsigned short *buf;
  192. ; unsigned short cnt;
  193.     procdef    lcsum,<<buf,ptr>,<cnt,word>>
  194.     pushds            ; save if using large model
  195.     push    si
  196.     ldptr    si,buf,ds    ; ds:si = buf
  197.     mov    cx,cnt        ; cx = cnt
  198.     cld            ; autoincrement si
  199.  
  200.     mov    ax,cx
  201.     shr    cx,1        ; cx /= 16, number of loop iterations
  202.     shr    cx,1
  203.     shr    cx,1
  204.     shr    cx,1
  205.  
  206.     inc    cx        ; make fencepost adjustment for 1st pass
  207.     and    ax,15        ; ax = number of words modulo 16
  208.     shl    ax,1        ; *=2 for word table index
  209.     lea    bx,jtable    ; bx -> branch table
  210.     add    bx,ax        ; index into jump table
  211.     clc            ; initialize carry = 0
  212.     mov    dx,0        ; clear accumulated sum
  213.     jmp    word ptr[bx]    ; jump into loop
  214.  
  215. ; Here the real work gets done. The numeric labels on the lodsw instructions
  216. ; are the targets for the indirect jump we just made.
  217. ;
  218. ; Each label corresponds to a possible remainder of (count / 16), while
  219. ; the number of times around the loop is determined by the quotient.
  220. ;
  221. ; The loop iteration count in cx has been incremented by one to adjust for
  222. ; the first pass.
  223. deloop:    lodsw
  224.     adc    dx,ax
  225. l15:    lodsw
  226.     adc    dx,ax
  227. l14:    lodsw
  228.     adc    dx,ax
  229. l13:    lodsw
  230.     adc    dx,ax
  231. l12:    lodsw
  232.     adc    dx,ax
  233. l11:    lodsw
  234.     adc    dx,ax
  235. l10:    lodsw
  236.     adc    dx,ax
  237. l9:    lodsw
  238.     adc    dx,ax
  239. l8:    lodsw
  240.     adc    dx,ax
  241. l7:    lodsw
  242.     adc    dx,ax
  243. l6:    lodsw
  244.     adc    dx,ax
  245. l5:    lodsw
  246.     adc    dx,ax
  247. l4:    lodsw
  248.     adc    dx,ax
  249. l3:    lodsw
  250.     adc    dx,ax
  251. l2:    lodsw
  252.     adc    dx,ax
  253. l1:    lodsw
  254.     adc    dx,ax
  255. l0:    loop    deloop        ; :-)
  256.  
  257.     adc    dx,0        ; get last carries
  258.     adc    dx,0
  259.     mov    ax,dx        ; result into ax
  260.     xchg    al,ah        ; byte swap result (8088 is little-endian)
  261.     pop    si
  262.     popds            ; all done
  263.     pret
  264.     pend    lcsum
  265. ;
  266. ; dos service routine used by JK1NNT installed by N3EUA
  267. ;
  268.     procdef    jkintdos,<<reg_a,word>,<reg_b,word>,<reg_d,word>>
  269.     mov    ax,reg_a
  270.     mov    bx,reg_b
  271.     mov    dx,reg_d
  272.     int    21h
  273.     pret
  274.     pend    jkintdos
  275. ;
  276. ; NEC PC-9801 speed setting routine by JK1NNT installed by N3EUA
  277. ;
  278.     procdef    set_speed,<<s_code,word>>
  279.     push    ds
  280.     mov    ax,40h
  281.     mov    ds,ax
  282.     mov    dx,s_code
  283.     mov    ds:[269h],dl
  284.     mov    dh,4ch
  285.     mov    ds:[268h],dh
  286.     pop    ds
  287.     mov    cl,0ah
  288.     int    0dch
  289.     pret
  290.     pend    set_speed
  291.  
  292. ;
  293. ; This routine is a generic int 21h handler, is used only by disk free
  294. ; routine.  Added by K3MC  3 Dec 87
  295. ;
  296. ;
  297. ; General-purpose int 21h caller, currently used only to return AX, BX, CX, DX
  298. ; for computing amount of free disk space, and amount of total disk space.
  299. ;
  300. ; declared as: void isfree();
  301. ;
  302. ; Called from C as:
  303. ;
  304. ; isfree(&ax,&bx,&cx,&dx)
  305. ; unsigned short ax,bx,cx,dx;
  306. ;
  307.     procdef    isfree,<<c_ax,ptr>,<c_bx,ptr>,<c_cx,ptr>,<c_dx,ptr>>
  308.     push    ax
  309.     push    bx
  310.     push    cx
  311.     push    dx
  312.     push    bp
  313.     push    si
  314.     push    di
  315.     ldptr    di,c_ax,ds
  316.     mov    ax,[di]
  317.     ldptr    di,c_bx,ds
  318.     mov    bx,[di]
  319.     ldptr    di,c_cx,ds
  320.     mov    cx,[di]
  321.     ldptr    di,c_dx,ds
  322.     mov    dx,[di]
  323.     int     21h
  324.     ldptr    di,c_ax,ds
  325.     mov    [di],ax
  326.     ldptr    di,c_bx,ds
  327.     mov    [di],bx
  328.     ldptr    di,c_cx,ds
  329.     mov    [di],cx
  330.     ldptr    di,c_dx,ds
  331.     mov    [di],dx
  332.     pop    di
  333.     pop    si
  334.     pop    bp
  335.     pop    dx
  336.     pop    cx
  337.     pop    bx
  338.     pop    ax
  339.     pret
  340.     pend    isfree
  341.  
  342.     end
  343.